package com.yl.auth.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.entity.Fangjianleixing;
import com.yl.auth.service.FangjianleixingService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ln
 * @since 2023-06-17
 */
@Api(tags = "数据字典-房间类型")
@RestController
@RequestMapping("/admin/auth/fangjianleixing")
public class FangjianleixingController {
    @Resource
    private FangjianleixingService fangjianleixingService;
    //查询所有的房间类型
    @ApiOperation(value = "查询所有的房间类型")
    @GetMapping("/findleixing/{page}/{limit}")
    public Result findleixing(@PathVariable @ApiParam("当前页") Integer page, @PathVariable @ApiParam("总条数") Integer limit){
        Page<Fangjianleixing> pagefarm = new Page<>(page,limit);
        IPage<Fangjianleixing> pagelei = fangjianleixingService.page(pagefarm);
        return Result.ok(pagelei);
    }
    //数字字典
    @ApiOperation(value = "数字字典")
    @GetMapping("/findzidian/{page}/{limit}")
    public Result findzidian(@PathVariable @ApiParam("当前页") Integer page,@PathVariable @ApiParam("总条数") Integer limit){
        Page<Fangjianleixing> pagefarm = new Page<>(page,limit);
        IPage<Fangjianleixing> pagezidian = fangjianleixingService.findzidian(pagefarm);
        return Result.ok(pagezidian);
    }
    //添加----------------------------------------------------------------
    @ApiOperation(value = "添加房屋类型")
    @PostMapping("/save")
    public Result save(@RequestBody Fangjianleixing fangjianleixing){
       fangjianleixingService.add(fangjianleixing);
       return Result.ok();
    }
    //修改----------------------------------------------------------------
    @ApiOperation(value = "根据id获取房屋类型")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id){
        Fangjianleixing byId = fangjianleixingService.getById(id);
        return Result.ok(byId);
    }
    @ApiOperation(value = "修改房屋类型")
    @PutMapping("/update")
    public Result update(@RequestBody Fangjianleixing fangjianleixing){
        fangjianleixingService.updateById(fangjianleixing);
        return Result.ok();
    }
    //删除----------------------------------------------------------------
    @ApiOperation(value = "根据id获取房屋类型2")
    @GetMapping("/getByIdleixing/{id}")
    public Result getByIdleixing(@PathVariable Long id){
        Fangjianleixing byId = fangjianleixingService.getByIdleixing(id);
        return Result.ok(byId);
    }
    @ApiOperation(value = "删除房间类型")
    @PostMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id){
        fangjianleixingService.removeById(id);
        return Result.ok();
    }
}

